// pages/applyrefund/applyrefund.js

var t = getApp(), e = t.requirejs("core"), a = t.requirejs("biz/order");

Page({

    /**
     * 页面的初始数据
     */
    data: {
        code: 1,
        tempFilePaths: "",
        delete: "",
        rtypeArr: [ "退款(仅退款不退货)", "退货退款", "换货" ],
        rtypeArrText: [ "退款", "退款", "换货" ],
        rtypeIndex: 1,
        reasonArr: [ "不想要了", "卖家缺货", "拍错了/订单信息错误", "其它" ],
        reasonIndex: null,
        images: [],
        logisticsArr: ['未收到货', '已收到货'],
        logisticsKey: null,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(e) {
        console.log(e, 'options');
        this.setData({
            options: e
        }), t.url(e), this.get_list(), this.get_list_two();
    },
    get_list: function() {
        var a = this;
        e.get("order/detail", a.data.options, function(e) {
            if (e.error > 0 && (5e4 != e.error && e.toast(e.message, "loading"), wx.redirectTo({
                url: "/pages/order/index"
            })), void 0 != e.nogift[0].fullbackgoods) var i = e.nogift[0].fullbackgoods.fullbackratio, o = e.nogift[0].fullbackgoods.maxallfullbackallratio, i = Math.round(i), o = Math.round(o);
            if (0 == e.error) {
                e.show = !0;
                var r = Array.isArray(e.ordervirtual);
                a.setData(e), a.setData({
                    ordervirtualtype: r,
                    fullbackgoods: e.nogift[0].fullbackgoods,
                    maxallfullbackallratio: o,
                    fullbackratio: i,
                    invoice: e.order.invoicename,
                    membercard_info: e.membercard_info
                });
            }
        });
    },
    get_list_two: function() {
        var t = this;
        e.get("order/refund", t.data.options, function(a) {
            console.log(a, 'aaaaaaaaaaaa');
            a.reasonIndex = null;

            t.setData({
                show: !0
            }), 0 == a.error ? (a.order.status < 2 && (a.rtypeArr = [ "退款(仅退款不退货)" ]), t.setData(a)) : (e.toast(a.message, "loading"),
            setTimeout(function() {
                wx.navigateBack();
            }, 1500));
        });
    },
    submit: function() {

        if(this.data.logisticsKey === null) return e.toast('请选择物流状态', "loading");
        if(this.data.reasonIndex === null) return e.toast('请选择退款原因', "loading");

        var t = {
            id: this.data.options.id,
            rtype: this.data.rtypeIndex,
            logistics: this.data.logisticsArr[this.data.logisticsKey],
            reason: this.data.reasonArr[this.data.reasonIndex],
            content: this.data.content,
            price: this.data.price,
            images: this.data.images
        };
        e.post("order/refund/submit", t, function(t) {
            0 == t.error ? wx.navigateBack() : e.toast(t.message, "loading");
        }, !0);
    },
    changeLogistics: function(e) {

        var a = this;
        var key = e.currentTarget.dataset.key;
        key = parseInt(key);

        if(this.data.logisticsKey == key) key = null;

        this.setData({
            'logisticsKey': key,
        });
    },
    changeReason: function(e) {
        console.log(e, 'eeee');
        var a = this;
        var key = e.currentTarget.dataset.key;
        key = parseInt(key);

        if(this.data.reasonIndex == key) key = null;

        this.setData({
            'reasonIndex': key,
        });
    },
    change: function(t) {
        var a = {};
        a[e.data(t).name] = t.detail.value, this.setData(a);
    },
    upload: function(t) {
        var a = this, i = e.data(t), s = i.type, r = a.data.images, n = a.data.imgs, o = i.index;
        "image" == s ? e.upload(function(t) {
            r.push(t.filename), n.push(t.url), a.setData({
                images: r,
                imgs: n
            });
        }) : "image-remove" == s ? (r.splice(o, 1), n.splice(o, 1), a.setData({
            images: r,
            imgs: n
        })) : "image-preview" == s && wx.previewImage({
            current: n[o],
            urls: n
        });
    },
    toggle: function(t) {
        var a = e.pdata(t).id;
        a = 0 == a || void 0 === a ? 1 : 0, this.setData({
            code: a
        });
    },
    edit: function(t) {
        this.setData({
            "order.refundstate": 0
        });
    },
    refundcancel: function(t) {
        a.refundcancel(this.data.options.id, function() {
            wx.navigateBack();
        });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },

    showModal: function() {
        // 显示遮罩层
        var animation = wx.createAnimation({
            duration: 200,
            timingFunction: "linear",
            delay: 0
        })
        this.animation = animation
        animation.translateY(300).step()
        this.setData({
            animationData: animation.export(),
            showModalStatus: true
        })
        setTimeout(function() {
            animation.translateY(0).step()
            this.setData({
                animationData: animation.export()
            })
        }.bind(this), 200)
    },

    hideModal: function() {
        // 隐藏遮罩层
        var animation = wx.createAnimation({
            duration: 200,
            timingFunction: "linear",
            delay: 0
        })
        this.animation = animation
        animation.translateY(300).step()
        this.setData({
            animationData: animation.export(),
        })
        setTimeout(function() {
            animation.translateY(0).step()
            this.setData({
                animationData: animation.export(),
                showModalStatus: false
            })
        }.bind(this), 200)
    },


    showModalTwo: function() {
        // 显示遮罩层
        var animation = wx.createAnimation({
            duration: 200,
            timingFunction: "linear",
            delay: 0
        })
        this.animation = animation
        animation.translateY(300).step()
        this.setData({
            animationDataTwo: animation.export(),
            showModalStatusTwo: true
        })
        setTimeout(function() {
            animation.translateY(0).step()
            this.setData({
                animationDataTwo: animation.export()
            })
        }.bind(this), 200)
    },

    hideModalTwo: function() {
        // 隐藏遮罩层
        var animation = wx.createAnimation({
            duration: 200,
            timingFunction: "linear",
            delay: 0
        })
        this.animation = animation
        animation.translateY(300).step()
        this.setData({
            animationDataTwo: animation.export(),
        })
        setTimeout(function() {
            animation.translateY(0).step()
            this.setData({
                animationDataTwo: animation.export(),
                showModalStatusTwo: false
            })
        }.bind(this), 200)
    }
})